﻿        using System;
        using System.Collections;
using ZoneFiveSoftware.Common.Data.Fitness;
using ZoneFiveSoftware.Common.Visuals;
using ZoneFiveSoftware.Common.Visuals.Chart;
using ZoneFiveSoftware.Common.Visuals.Fitness;

namespace BENBUN.Utils
{
    internal class fillCategoryList
    {
        private static IList _catList = new ArrayList();
        private static IActivityCategory _catTop;

        public static IActivityCategory catTop
        {
            get { return _catTop; }
            set
            {
                _catTop = value;
                _catList.Clear();
                _catList.Add(_catTop.ReferenceId);

                foreach (IActivityCategory category in _catTop.SubCategories)
                {
                    addFromTree(category);
                }
               // save();
            }
        }

        public static void addFromTree(IActivityCategory thisBranch)
        {
            _catList.Add(thisBranch.ReferenceId);
            foreach (IActivityCategory category in thisBranch.SubCategories)
            {
                addFromTree(category);
            }
        }


        public static IList CategoryList
        {
            get { return _catList; }
        }
    }
    internal class YVCategoryContentProvider : TreeList.DefaultContentProvider
    {
        public override IList GetChildren(object parentElement)
        {
            if (!(parentElement is IActivityCategory))
            {
                return null;
            }
            IList list = new ArrayList();
            foreach (IActivityCategory category in ((IActivityCategory)parentElement).SubCategories)
            {
                list.Add(category);
            }
            return list;
        }

        public override object GetParent(object element)
        {
            if (element is IActivityCategory)
            {
                return ((IActivityCategory)element).Parent;
            }
            return null;
        }

        public override bool HasChildren(object element)
        {
            return ((element is IActivityCategory) && (((IActivityCategory)element).SubCategories.Count > 0));
        }
    }
}
